package org.testing.model;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import org.testing.model.questions.Question;
import org.testing.model.results.Result;
import org.testing.model.userAnswers.UserAnswer;
import org.testing.InOutManager;

public class Test {
	private boolean isReadyToTest = false;
	private List<Question> questions;
	private List<Result> results = new ArrayList<Result>();
	private InOutManager inOut;

	public Test(InOutManager inOut) {
		this.inOut = inOut;
	}

	public void loadQuestions(List<Question> importedQuestions) {
		questions = importedQuestions;
		becameReadyToTest();
	}

	public List<Result> conductTheTest() {
		doBeforeTest();
		for (int questionCount = 0; questionCount < questions.size(); questionCount++) {
			Question currentQestion = questions.get(questionCount);
			showNumberOfQuestion(questionCount + 1);
			inOut.outPut(currentQestion.getHelp());
			inOut.outPut(currentQestion.toString());
			UserAnswer userAnswer = currentQestion.readUserAnswer(inOut);
			results.add(currentQestion.check(userAnswer));
		}
		return results;
	}

	private void showNumberOfQuestion(int number) {
		inOut.outPut("question number: ");
		inOut.outPut(number + "\n");
		
	}

	private void doBeforeTest() {
		showHelp();
	}

	private void showHelp() {
		inOut.outPut("Hello! This is java test, using OOP \n");
	}

	private void becameReadyToTest() {
		isReadyToTest = true;
	}

	public boolean isReadyToTest() {
		return isReadyToTest;
	}
}
